﻿
using Xacml.Core.Interfaces;
using Xacml.Core.Runtime;
using Xacml.Core.Runtime.DataTypes;

namespace Xacml.Core.Runtime.Functions
{
  public class DateTimeAddDayTimeDuration : FunctionBase
  {
    public override string Id
    {
      get
      {
        return "urn:oasis:names:tc:xacml:1.0:function:dateTime-add-dayTimeDuration";
      }
    }

    public override IDataType Returns
    {
      get
      {
        return (IDataType) DataTypeDescriptor.DateTime;
      }
    }

    public override IDataType[] Arguments
    {
      get
      {
        return new IDataType[2]
        {
          (IDataType) DataTypeDescriptor.DateTime,
          (IDataType) DataTypeDescriptor.DayTimeDuration
        };
      }
    }

    public override EvaluationValue Evaluate(EvaluationContext context, params IFunctionParameter[] args)
    {
      System.DateTime dateTime = this.GetDateTimeArgument(args, 0);
      DayTimeDuration durationArgument = this.GetDayTimeDurationArgument(args, 1);
      dateTime = dateTime.AddDays((double) durationArgument.Days);
      dateTime = dateTime.AddHours((double) durationArgument.Hours);
      dateTime = dateTime.AddMinutes((double) durationArgument.Minutes);
      dateTime = dateTime.AddSeconds((double) durationArgument.Seconds);
      return new EvaluationValue((object) dateTime, (IDataType) DataTypeDescriptor.DateTime);
    }
  }
}
